package com.yonyou.pmclouds.plan.processor;

import com.yonyou.pmclouds.basecom.bp.processor.MultiProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.plan.entity.PlanProgressVO;
import com.yonyou.pmclouds.plan.entity.ScheduleItemVO;
import com.yonyou.pmclouds.plan.rmiitf.IScheduleProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ScheduleItemInsertAfterProcessor implements MultiProcessor<ScheduleItemVO> {

    @Autowired
    private IScheduleProgressService progressService;

    @Override
    public void process(ScheduleItemVO[] vos, ScheduleItemVO[] origs) throws BusinessException {
        progressService.insert(getProgressVO(vos));
    }

    private PlanProgressVO[] getProgressVO(ScheduleItemVO[] vos){
        List<PlanProgressVO> progressVOS = new ArrayList<>(vos.length);
        for(ScheduleItemVO itemVO : vos){
            PlanProgressVO progressVO = new PlanProgressVO();
            progressVO.setPkPlan(itemVO.getPkScheduleItem());
            progressVO.setProgress(0);
            progressVOS.add(progressVO);
        }

        return progressVOS.toArray(new PlanProgressVO[]{});
    }
}
